package com.woniuxy.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.entity.Movie;
import com.woniuxy.mapper.MovieMapper;
import com.woniuxy.service.MovieService;
import com.woniuxy.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MovieServiceimpl extends ServiceImpl<MovieMapper, Movie> implements MovieService {
   @Autowired
   private MovieMapper movieMapper;

    @Override
    public List<Movie> ByNew(int new_category) {
        return movieMapper.ByNew(new_category);
    }

    @Override
    public PageBean<Movie> ByCategoryId(Integer categoryId, int p, int n) {
        PageBean<Movie> pageBean = new PageBean<>();
        //查询第几页每页多少条
        PageHelper.startPage(p,10);
        Page<Movie> data =(Page)movieMapper.ByCategoryId(categoryId,n);
        pageBean.setData(data.getResult());//设置数据
        pageBean.setPageSize(10);//一页显示多少数据
        pageBean.setCurrPage(p);//查看第几页
        pageBean.setNumOfCurrPage(data.size());//当前也数量
        pageBean.setTotalPage(data.getPages());//总共多少页
        pageBean.setTotalNums((int)data.getTotal());//总页数？
        return pageBean;
    }

    @Override
    public PageBean<Movie> all(Integer p,int n) {
        PageBean<Movie> pageBean = new PageBean<>();
        //查询第几页每页多少条
        PageHelper.startPage(p,12);
        Page<Movie> data =(Page)movieMapper.all(n);
        pageBean.setData(data.getResult());//设置数据
        pageBean.setPageSize(10);//一页显示多少数据
        pageBean.setCurrPage(p);//查看第几页
        pageBean.setNumOfCurrPage(data.size());//当前也数量
        pageBean.setTotalPage(data.getPages());//总共多少页
        pageBean.setTotalNums((int)data.getTotal());//总页数？
        return pageBean;
    }

    @Override
    public List<Movie> ByRunk() {

        return movieMapper.Byrunk();
    }
}
